package org.fcs.framework.generator;

import httl.Engine;
import httl.Template;

import java.io.IOException;
import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/2/23.
 */
public class GeneratorMapperXml implements Generator {
    @Override
    public String process(String tableName) {
        Engine engine = Engine.getEngine();
        Template template = null;
        String result = "";
        try {
            template = engine.getTemplate("template/mapper.xml.httl");

            Map<String, Object> parameters = new HashMap<String, Object>();
            parameters.put("table", DataInfo.readTableName(tableName));
            List<Map<String, Object>> columns= DataInfo.readColData(tableName);
            parameters.put("primaryKey",columns.get(0).get("name"));
            parameters.put("cols", columns);
            
            result = (String) template.evaluate(parameters);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return result;
    }
}
